package com.stephentuso.welcomeexample;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

/**
 * Created by stephentuso on 11/16/16.
 */

public class ExampleActionAbility extends Ability {

    public static final String KEY_ACTION_TITLE = "action_title";

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_example_action);

        String action = getIntent().getStringParam(KEY_ACTION_TITLE);

        Text textView = (Text) findComponentById(ResourceTable.Id_text);
        textView.setText(getString(ResourceTable.String_example_action_description, action));

        findComponentById(ResourceTable.Id_button).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component v) {
                complete();
            }
        });

    }

    private void complete() {
        setResult(-1, null);
        terminateAbility();
    }

}
